package csci6450.chickenFriedFS.nuggetCore;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class ChickenFile implements Serializable {

    private String fileName;
    private List<Nugget> nuggets;
    private int fileNuggetCount;

    public ChickenFile(String fileName, int nuggetCount) {
        this.fileName = fileName;
        this.fileNuggetCount = nuggetCount;
        this.nuggets = new ArrayList<Nugget>();
    }

    public String getFileName() {
        return fileName;
    }

    public void setFileName(String val) {
        this.fileName = val;
    }

    public int getFileNuggetCount() {
        return fileNuggetCount;
    }

    public void setFileNuggetCount(int val) {
        this.fileNuggetCount = val;
    }

    public boolean isFullyFried() {
        return this.nuggets.size() == this.fileNuggetCount;
    }

    public boolean addNugget(Nugget add) {
        boolean added = false;
        if (add.getParentFilename().equals(this.fileName)) {
            this.removeNugget(add);
            this.nuggets.add(add);

            added = true;
        }
        return added;
    }

    private void removeNugget(Nugget add) {
        boolean match = false;
        for (int i = 0; !match && i < this.nuggets.size(); i = i + 1) {
            if (this.nuggets.get(i).getNuggetIdentifier().equals(add.getNuggetIdentifier())) {
                match = true;
                this.nuggets.remove(i);
            }
        }
    }

    public List<Nugget> getNuggets() {
        return this.nuggets;
    }
}

